<?php

/**
 * px_note actions.
 *
 * @package    tmdb
 * @subpackage px_note
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class mc_noteActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->note_list = Doctrine::getTable('Note')
      ->createQuery('a')
 			->where('a.client_id = ?',$request->getParameter('client_id'))
      ->execute();
		$this->client_id = ($request->getParameter('client_id'));
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->note = Doctrine::getTable('Note')->find(array($request->getParameter('id')));
		$this->client_id = ($this->note->getclient_id());
    $this->forward404Unless($this->note);
  }

  public function executeNew(sfWebRequest $request)
  {
		$note = new Note();
		$note->setclient_id($request->getParameter('client_id'));
		$this->client_id = ($request->getParameter('client_id'));
    $this->form = new NoteForm($note);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));
		$client_id = ($request->getParameter('client_id'));
    $this->form = new NoteForm();

    $this->processForm($request, $this->form, $client_id);
		$this->client_id = ($request->getParameter('client_id'));
    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($note = Doctrine::getTable('Note')->find(array($request->getParameter('id'))), sprintf('Object note does not exist (%s).', array($request->getParameter('id'))));
		$this->client_id = ($note->getclient_id());
    $this->form = new NoteForm($note);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($note = Doctrine::getTable('Note')->find(array($request->getParameter('id'))), sprintf('Object note does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new NoteForm($note);
		$client_id = ($request->getParameter('client_id'));
    $this->processForm($request, $this->form, $client_id);
		$this->client_id = ($request->getParameter('client_id'));
    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($note = Doctrine::getTable('Note')->find(array($request->getParameter('id'))), sprintf('Object note does not exist (%s).', array($request->getParameter('id'))));
		$this->client_id = ($note->getclient_id());
    $note->delete();

    $this->redirect('mc_note/index?client_id='.$this->client_id);
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $note = $form->save();
			$client_id = $note->getclient_id();
			$this->client_id = $client_id;
      $this->redirect('mc_note/index?client_id='.$client_id);
    }
  }
}
